home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 1
/
Atari Mega Archive - Volume 1.iso
/
gnu
/
gawk
/
cawf2st.zoo
/
pass2.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-04-12
|
53KB
|
1,266 lines
/*
* pass2.c - cawf(1) pass 2 function
*/
/*
* Copyright (c) 1991 Purdue University Research Foundation,
* West Lafayette, Indiana 47907. All rights reserved.
*
* Written by Victor A. Abell <abe@mace.cc.purdue.edu>, Purdue
* University Computing Center. Not derived from licensed software;
* derived from awf(1) by Henry Spencer of the University of Toronto.
*
* Permission is granted to anyone to use this software for any
* purpose on any computer system, and to alter it and redistribute
* it freely, subject to the following restrictions:
*
* 1. The author is not responsible for any consequences of use of
* this software, even if they arise from flaws in it.
*
* 2. The origin of this software must not be misrepresented, either
* by explicit claim or by omission. Credits must appear in the
* documentation.
*
* 3. Altered versions must be plainly marked as such, and must not
* be misrepresented as being the original software. Credits must
* appear in the documentation.
*
* 4. This notice may not be removed or altered.
*/
#include "cawf.h"
#ifdef UNIX
#ifdef USG
#include <string.h>
#else
#include <strings.h>
#endif
#else
#include <string.h>
#endif
#include <ctype.h>
/*
* Pass2(line) - process the nroff commands in a line and break
* text into words for pass 3
*/
void
Pass2(line)
char *line;
{
char buf[MAXLINE]; /* working buffer */
char c; /* character buffer */
double d; /* temporary double */
double exscale; /* expression scaling factor */
double expr[MAXEXP]; /* expressions */
char exsign[MAXEXP]; /* expression signs */
int i, j, k; /* temporary indexes */
int inword; /* word processing status */
int nexpr; /* number of expressions */
char nm[4]; /* name */
int nsp; /* number of spaces */
char op; /* expression term operator */
char opstack[MAXSP]; /* expression operation stack */
char period; /* end of word status */
char *s1, *s2, *s3, *s4, *s5; /* temporary string pointers */
double sexpr[MAXEXP]; /* signed expressions */
int sp; /* expression stack pointer */
char ssign; /* expression's starting sign */
int tabpos; /* tab position */
double tscale; /* term scaling factor */
double tval; /* term value */
double val; /* term value */
double valstack[MAXSP]; /* expression value stack */
char xbuf[MAXLINE]; /* expansion buffer */
if (line == NULL) {
/*
* End of macro expansion.
*/
Pass3(DOBREAK, "need", NULL, 999); /* flush page */
return;
}
/*
* Adjust line number.
*/
if (Lockil == 0)
P2il++;
/*
* Empty line - "^[ \t]*$".
*/
if (regexec(Pat[6].pat, line)) {
Pass3(DOBREAK, "space", NULL, 0);
return;
}
/*
* Line begins with white space.
*/
if (*line == ' ' || *line == '\t') {
Pass3(DOBREAK, "flush", NULL, 0);
Pass3(0, "", NULL, 0);
}
/*
* Line contains text (not an nroff command).
*/
if (*line != '.') {
if (Font[0] == 'R' && Backc == 0 && Aftnxt == NULL
&& regexec(Pat[7].pat, line) == 0) {
/*
* The font is Roman, there is no "\\c" or "after next"
* trap pending and and the line has no '\\', '\t', '-',
* or " " (regular expression "\\|\t|-| ").
*
* Output each word of the line as "<length> <word>".
*/
for (s1 = line;;) {
while (*s1 && *s1 == ' ')
s1++;
if (*s1 == '\0')
break;
for (s2 = s1, s3 = buf; *s2 && *s2 != ' ';)
*s3++ = Trtbl[(int)*s2++];
*s3 = '\0';
Pass3((s2 - s1), buf, NULL, 0);
s1 = *s2 ? ++s2 : s2;
}
/*
* Line terminates with punctuation and optional
* bracketing (regular expression "[.!?:][\])'\"*]*$").
*/
if (regexec(Pat[8].pat, line))
Pass3(NOBREAK, "gap", NULL, 2);
if (Centering > 0) {
Pass3(DOBREAK,"center", NULL, 0);
Centering--;
} else if (Fill == 0)
Pass3(DOBREAK, "flush", NULL, 0);
return;
}
/*
* Line must be scanned a character at a time.
*/
inword = nsp = tabpos = 0;
period = '\0';
for (s1 = line;; s1++) {
/*
* Space or TAB causes state transition.
*/
if (*s1 == '\0' || *s1 == ' ' || *s1 == '\t') {
if (inword) {
if (!Backc) {
Word[Wordx] = '\0';
Pass3(Wordl, Word, NULL, 0);
if (Uhyph) {
Pass3(NOBREAK, "nohyphen",
NULL, 0);
}
}
inword = 0;
nsp = 0;
}
if (*s1 == '\0')
break;
} else {
if (inword == 0) {
if (Backc == 0) {
Wordl = Wordx = 0;
Uhyph = 0;
}
Backc = 0;
inword = 1;
if (nsp > 1) {
Pass3(NOBREAK, "gap", NULL,
nsp);
}
}
}
/*
* Process a character.
*/
switch (*s1) {
/*
* Space
*/
case ' ':
nsp++;
period = '\0';
break;
/*
* TAB
*/
case '\t':
tabpos++;
if (tabpos <= Ntabs) {
Pass3(NOBREAK, "tabto", NULL,
Tabs[tabpos-1]);
}
nsp = 0;
period = '\0';
break;